/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package SYSGEST.br.Login;

import sysgest.conexao.HibernateUtil;
import Telas.TelaLogin;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author AELSON
 */
public class LoginDAO {
    private Session sessao;
    private Transaction transacao;
    
    public void salvar(Login login){
        sessao = HibernateUtil.getSessionFactory()
                .openSession();
        transacao = sessao.beginTransaction();
        sessao.save(login);
        transacao.commit();
        sessao.close();
    }
    
    public boolean logar(String log, String senha) {
        sessao = HibernateUtil.getSessionFactory().openSession();
        transacao = sessao.beginTransaction();
        Login login = (Login) sessao.createCriteria(Login.class)
                .add(Restrictions.eq(("log"), log))
                .add(Restrictions.eq("senha", senha)).uniqueResult();
        if (login == null) {
            return false;

        } else {
            return true;
        }

    }
}
